package com.nbsaas.boot.product.rest.convert;

import com.nbsaas.boot.product.data.entity.Product;
import com.nbsaas.boot.product.api.domain.request.ProductRequest;

import org.springframework.beans.BeanUtils;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
            import com.nbsaas.boot.jpa.data.entity.User;
            import com.nbsaas.boot.product.data.entity.ProductCatalog;

/**
* 产品请求对象转换成实体对象
*/

public class ProductEntityConvert  implements Converter<Product, ProductRequest> {

    @Override
    public Product convert(ProductRequest source) {
        Product result = new Product();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getCreator()!=null){
                    User creator =new User();
                    creator.setId(source.getCreator());
                    result.setCreator(creator);
                    }
                    if(source.getProductCatalog()!=null){
                    ProductCatalog productCatalog =new ProductCatalog();
                    productCatalog.setId(source.getProductCatalog());
                    result.setProductCatalog(productCatalog);
                    }
        return result;
    }
}

